package uiLayer;

import uiUtil.AbstractEditableCustomTable;

public class EditableOrderLineWrapperTable extends AbstractEditableCustomTable<OrderLineWrapper> {
	
	public EditableOrderLineWrapperTable() {
		
		super();
		super.setColNames("Varenr.", "Navn", "Pris", "Antal", "Tilføj/Fjern");
		//Property on JTable which stops editing and saves changes when focus lost from the table:
		putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); 
		
	}

	@Override
	public boolean doIsCellEditable(int rowIndex, int columnIndex) {
		
		if (columnIndex < 3) {
			return false;
		}
		else {
			return true;
		}
		
	}

	@Override
	public void doSetValueAt(Object aValue, int col, OrderLineWrapper ow) {
		
		System.out.println("doSetValueAt() " + aValue + ", " + col);
		switch (col) {
		case 3:
			//ol.setAmount((Integer)aValue);
			ow.getOrderLine().setAmount((Integer)aValue);
			break;
		case 4:
			//ol.setAdded((Boolean)aValue);
			ow.setAdded((Boolean)aValue);
			break;
		}
		
	}

	@Override
	public Object getCellValue(int col, OrderLineWrapper ow) {
		
		Object res = null;
		switch (col) {
			case 0:
				//res = ol.getProduct().getProductID();
				res = ow.getOrderLine().getProduct().getProductID();
				break;
			case 1:
				//res = ol.getProduct().getName();
				res = ow.getOrderLine().getProduct().getName();
				break;
			case 2:
				//res = ol.getProduct().getSalesPrice();
				res = ow.getOrderLine().getProduct().getSalesPrice();
				break;
			case 3:
				//res = ol.getAmount();
				res = ow.getOrderLine().getAmount();
				break;
			case 4:
				//res = ol.isAdded();
				res = ow.isAdded();
				break;
		}
		return res;
	}

}
